package com.supersoul.myself.controller.oss;


import com.aliyun.oss.OSS;
import com.aliyun.oss.model.PutObjectResult;
import com.supersoul.myself.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/oss")
public class OssController {

    private String bucketName = "blog-beijing-com";

    @Autowired
    private OSS ossClient;

    @RequestMapping("/upload")
    public R upload(MultipartFile multipartFile) throws IOException {
        PutObjectResult putObjectResult = ossClient.putObject(bucketName, multipartFile.getOriginalFilename(), multipartFile.getInputStream());
        return R.success(putObjectResult);
    }

}
